package com.numberone.web.controller.goodsDetail;

import com.numberone.common.annotation.Log;
import com.numberone.common.base.AjaxResult;
import com.numberone.common.enums.BusinessType;
import com.numberone.common.page.TableDataInfo;
import com.numberone.common.utils.poi.ExcelUtil;
import com.numberone.framework.web.base.BaseController;
import com.numberone.system.domain.GoodsDetail;
import com.numberone.system.service.IGoodsDetailService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 商品具体 信息操作处理
 * 
 * @author numberone
 * @date 2020-09-28
 */
@Controller
@RequestMapping("/system/goodsDetail")
public class GoodsDetailController extends BaseController
{
    private String prefix = "system/goodsDetail";
	
	@Autowired
	private IGoodsDetailService goodsDetailService;
	
	@RequiresPermissions("system:goodsDetail:view")
	@GetMapping()
	public String goodsDetail()
	{
	    return prefix + "/goodsDetail";
	}
	
	/**
	 * 查询商品具体列表
	 */
	@RequiresPermissions("system:goodsDetail:list")
	@PostMapping("/list")
	@ResponseBody
	public TableDataInfo list(GoodsDetail goodsDetail)
	{
		startPage();
        List<GoodsDetail> list = goodsDetailService.selectGoodsDetailList(goodsDetail);
		return getDataTable(list);
	}
	
	
	/**
	 * 导出商品具体列表
	 */
	@RequiresPermissions("system:goodsDetail:export")
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(GoodsDetail goodsDetail)
    {
    	List<GoodsDetail> list = goodsDetailService.selectGoodsDetailList(goodsDetail);
        ExcelUtil<GoodsDetail> util = new ExcelUtil<GoodsDetail>(GoodsDetail.class);
        return util.exportExcel(list, "goodsDetail");
    }
	
	/**
	 * 新增商品具体
	 */
	@GetMapping("/add")
	public String add()
	{
	    return prefix + "/add";
	}
	
	/**
	 * 新增保存商品具体
	 */
	@RequiresPermissions("system:goodsDetail:add")
	@Log(title = "商品具体", businessType = BusinessType.INSERT)
	@PostMapping("/add")
	@ResponseBody
	public AjaxResult addSave(GoodsDetail goodsDetail)
	{		
		return toAjax(goodsDetailService.insertGoodsDetail(goodsDetail));
	}

	/**
	 * 修改商品具体
	 */
	@GetMapping("/edit/{id}")
	public String edit(@PathVariable("id") Long id, ModelMap mmap)
	{
		GoodsDetail goodsDetail = goodsDetailService.selectGoodsDetailById(id);
		mmap.put("goodsDetail", goodsDetail);
	    return prefix + "/edit";
	}
	
	/**
	 * 修改保存商品具体
	 */
	@RequiresPermissions("system:goodsDetail:edit")
	@Log(title = "商品具体", businessType = BusinessType.UPDATE)
	@PostMapping("/edit")
	@ResponseBody
	public AjaxResult editSave(GoodsDetail goodsDetail)
	{		
		return toAjax(goodsDetailService.updateGoodsDetail(goodsDetail));
	}
	
	/**
	 * 删除商品具体
	 */
	@RequiresPermissions("system:goodsDetail:remove")
	@Log(title = "商品具体", businessType = BusinessType.DELETE)
	@PostMapping( "/remove")
	@ResponseBody
	public AjaxResult remove(String ids)
	{		
		return toAjax(goodsDetailService.deleteGoodsDetailByIds(ids));
	}
	
}
